Work around bugs in the runlength encoder by forcing rowstride * height to
authorMatthias Clasen <mclasen@redhat.com>
Tue, 24 Aug 2004 13:54:26 +0000 (13:54 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 24 Aug 2004 13:54:26 +0000 (13:54 +0000)
2004-08-24  Matthias Clasen  <mclasen@redhat.com>

* gdk-pixdata.c (gdk_pixdata_from_pixbuf): Work around bugs in
the runlength encoder by forcing rowstride * height to be
divisible by bpp.  (#150882)

docs/reference/ChangeLog
docs/reference/gdk-pixbuf/gdk-pixbuf-csource.xml
gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixdata.c

index dcfb8c0658ba638d817a970ebd460ba75170b7be..f568b06dd9f69aeeccca735bb10f2d89e2e7630c 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-24  Matthias Clasen  <mclasen@redhat.com>
+
+       * gdk-pixbuf/gdk-pixbuf-csource.xml: Document bugs of
+       the runlength encoder.
+
 Tue Aug 24 02:28:21 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtk-docs.sgml: Include visual index.
index fdb785405d25849e87681ca17e994cea24194ce0..74463b167055d0e5478b7be3e2fd7ea14193c2fb 100644 (file)
@@ -154,7 +154,9 @@ Gtk+ distribution, available from <ulink url="http://www.gtk.org">www.gtk.org</u
 
 <refsect1><title>Bugs</title>
 <para>
-None known yet.
+The runlength encoder gets out of sync with the pixel boundaries, since
+it includes the rowstride padding in the encoded stream. Furthermore, it
+generates pixbufs with suboptimal rowstride in some cases.
 </para>
 </refsect1>
 
index 7afc519bc52b81726877b76eacdf165bcb1ac741..81b029153a6cb32ca60a625e2e8ab3b9b0550a12 100644 (file)
@@ -1,3 +1,9 @@
+2004-08-24  Matthias Clasen  <mclasen@redhat.com>
+
+       * gdk-pixdata.c (gdk_pixdata_from_pixbuf): Work around bugs in
+       the runlength encoder by forcing rowstride * height to be 
+       divisible by bpp.  (#150882)
+
 Sun Aug 22 03:20:56 2004  Matthias Clasen  <maclas@gmx.de>
 
        * pixops/pixops.c (pixops_scale_nearest): Fix a mixup in the handling
index 66f665877f3d5554476539028e0992bd5135a9f8..e027ed659dcfef32add7d1afe6e937c3b6c3aef0 100644 (file)
@@ -328,16 +328,36 @@ gdk_pixdata_from_pixbuf (GdkPixdata      *pixdata,
     {
       guint pad, n_bytes = rowstride * height;
       guint8 *img_buffer_end, *data;
+      GdkPixbuf *buf = NULL;
 
+      if (n_bytes % bpp != 0) 
+       {
+         rowstride = pixbuf->width * bpp;
+         n_bytes = rowstride * height;
+         data = g_malloc (n_bytes);
+         buf = gdk_pixbuf_new_from_data (data,
+                                         GDK_COLORSPACE_RGB,
+                                         pixbuf->has_alpha, 8,
+                                         pixbuf->width,
+                                         pixbuf->height,
+                                         rowstride,
+                                         NULL, NULL);
+         gdk_pixbuf_copy_area (pixbuf, 0, 0, pixbuf->width, pixbuf->height,
+                               buf, 0, 0);
+       }
+      else
+       buf = pixbuf;
       pad = rowstride;
       pad = MAX (pad, 130 + n_bytes / 127);
       data = g_new (guint8, pad + n_bytes);
       free_me = data;
       img_buffer = data;
       img_buffer_end = rl_encode_rgbx (img_buffer,
-                                      pixbuf->pixels, pixbuf->pixels + n_bytes,
+                                      buf->pixels, buf->pixels + n_bytes,
                                       bpp);
       length = img_buffer_end - img_buffer;
+      if (buf != pixbuf)
+       g_object_unref (buf);
     }
   else
     {